<template>
  <div class="mod-config">
    <basic-container>
      <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
        <el-form-item prop="parkName">
          <el-input placeholder="请输入停车场名称" clearable v-model="queryParams.parkName" />
        </el-form-item>
        <el-form-item prop="parkType">
          <el-select v-model="queryParams.parkType" clearable class="m-2" placeholder="停车场类型">
            <el-option v-for="item in dicts.park_type" :key="item.value" :label="item.label" :value="item.value" />
          </el-select>
          <!-- <template #="scope">
            <dict-tag :options="dicts.park_type" :value="scope.row.parkType" />
          </template> -->
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-button icon="el-icon-plus" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        </el-form-item>
      </el-form>

      <div class="avue-crud">
        <el-table :data="dataList" border v-loading="dataListLoading">
          <el-table-column prop="id" header-align="center" align="center" label="停车场ID">
          </el-table-column>
          <el-table-column prop="parkName" header-align="center" align="center" label="停车场名称">
          </el-table-column>
          <el-table-column prop="oneDayMaxFee" header-align="center" align="center" label="每天最高收费">
          </el-table-column>
          <el-table-column prop="spaceCount" header-align="center" align="center" label="本停车场停车位数">
          </el-table-column>
          <el-table-column prop="address" header-align="center" align="center" label="车场位置">
          </el-table-column>
          <el-table-column prop="parkType" header-align="center" align="center" label="停车场类型">
            <template #="scope">
              <dict-tag :options="dicts.park_type" :value="scope.row.parkType" />
            </template>
          </el-table-column>
          <el-table-column prop="networkState" header-align="center" align="center" label="停车场网络状态">
            <template #="scope">
              <el-tag v-if="scope.row.networkState == '1'">正常</el-tag>
              <el-tag type="danger" v-else>异常</el-tag>
            </template>
          </el-table-column>
          <el-table-column header-align="center" align="center" label="操作">
            <template #="scope">
              <el-button link type="primary" size="small" icon="el-icon-edit" @click="addOrUpdateHandle(scope.row.id)">
                修改
              </el-button>
              <el-button link type="primary" size="small" icon="el-icon-delete" @click="deleteHandle(scope.row.id)">删除
              </el-button>
              <el-dropdown @command="handleCommand" trigger="click">
                <span class="el-dropdown-link">
                  <el-icon class="el-icon--right">
                    <arrow-down />
                  </el-icon> 更多
                </span>
                <template #dropdown>
                  <el-dropdown-menu>
                    <el-dropdown-item :command="handleCommandParams('a',scope.row.id)">查看秘钥</el-dropdown-item>
                    <el-dropdown-item :command="handleCommandParams('b',scope.row.id)">查看提前交费二维码</el-dropdown-item>
                    <el-dropdown-item :command="handleCommandParams('c',scope.row.id)">查看微信包月二维码</el-dropdown-item>
                    <el-dropdown-item :command="handleCommandParams('d',scope.row.id)">子车场管理</el-dropdown-item>
                    <el-dropdown-item :command="handleCommandParams('e',scope.row.id)">停车场区域</el-dropdown-item>
                    <el-dropdown-item :command="handleCommandParams('f',scope.row.id)">特别放行原因</el-dropdown-item>
                    <el-dropdown-item :command="handleCommandParams('g',scope.row.id)">减免分类管理</el-dropdown-item>
                  </el-dropdown-menu>
                </template>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>
      </div>

      <div class="avue-crud__pagination">
        <el-pagination @size-change="sizeChangeHandle" @current-change="currentChangeHandle"
          :current-page="queryParams.current" :page-sizes="[10, 20, 50, 100]" :page-size="queryParams.size"
          :total="totalPage" background layout="total, sizes, prev, pager, next, jumper">
        </el-pagination>
      </div>
      <!-- 弹窗, 新增 / 修改 -->
      <table-form v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></table-form>
      <secret-key v-if="secretKeyShow" ref="secretKeyDate"></secret-key>
      <pay-fee v-if="payFeeCode" ref="payFeeDate"></pay-fee>
    </basic-container>
  </div>
</template>

<script>
import { fetchList, delObj } from '@/api/stop/parking'
import TableForm from './components/tableForm.vue'
import SecretKey from './components/secretKey.vue'
import PayFee from "./components/payFee.vue";
import { mapGetters } from 'vuex'
export default {
  dicts: ['park_type'],
  data () {
    return {
      queryParams: {
        current: 1,
        size: 10,
        isRoad: 0,
      },

      dataForm: {
        key: ''
      },
      dataList: [],

      totalPage: 0,
      dataListLoading: false,
      addOrUpdateVisible: false,
      secretKeyShow: false,
      payFeeCode: false,
    }
  },
  components: {
    TableForm, SecretKey, PayFee
  },
  created () {
    this.getDataList()
  },

  computed: {
    ...mapGetters(['permissions'])
  },
  methods: {
    handleCommandParams (command, parkingId) {
      return {
        'command': command,
        'parkingId': parkingId
      }
    },
    handleCommand (item) {
      //   console.log(item)
      switch (item.command) {
        case 'a':
          this.secretKeyShow = true
          this.$nextTick(() => {
            this.$refs.secretKeyDate.init(item.parkingId)
          })
          break;
        case 'b':
          this.payFeeCode = true
          this.$nextTick(() => {
            this.$refs.payFeeDate.init()
          })
          break;
        case 'c':
          this.payFeeCode = true
          this.$nextTick(() => {
            this.$refs.payFeeDate.WeChatInit()
          })
          break;
        case 'd':
          this.$router.push({
            path: "/stop/childrenPark",
            query: {
              parentParkId: item.parkingId
            },
          });
          break;
        case 'e':
          this.$router.push({
            path: "/stop/region/index",
            query: {
              parkId: item.parkingId
            },
          });
          break;
        case 'f':
          this.$router.push({
            path: "/stop/specialpasstype/index",
            query: {
              parkId: item.parkingId
            },
          });
          break;
        case 'g':
          this.$router.push({
            path: "/stop/relieftype/index",
            query: {
              parkId: item.parkingId,
            },
          });
          break;
      }
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      fetchList(Object.assign(this.queryParams)).then(response => {
        this.dataList = response.data.data.records
        this.totalPage = response.data.data.total
      })
      this.dataListLoading = false
    },
    // 每页数
    sizeChangeHandle (val) {
      this.queryParams.size = val
      this.queryParams.current = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.queryParams.current = val
      this.getDataList()
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      //   console.log(id);
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })

    },
    // 删除
    deleteHandle (id) {
      this.$confirm('是否确认删除ID为' + id, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(function () {
        return delObj(id)
      }).then(data => {
        this.$message.success('删除成功')
        this.getDataList()
      }).catch(() => { })
    },
    handleQuery () {
      this.queryParams.current = 1;
      this.getDataList()
    },
    resetQuery () {
      this.queryParams = {
        current: 1,
        size: 10,
        isRoad: 0,
      };
      //   this.resetForm("queryForm");
      this.handleQuery();
    }
  }
}
</script>
<style scoped>
.el-dropdown-link {
  color: rgb(128, 128, 241);
  font-size: 12px;
  margin-top: 13%;
  cursor: pointer;
}
</style>
